package com.ikun.appointment.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ikun.common.entity.Convention;
import org.apache.ibatis.annotations.Select;

/**
 * 挂号预约表(Convention)表数据库访问层
 *
 * @author makejava
 * @since 2024-02-26 10:08:25
 */
public interface ConventionDao extends BaseMapper<Convention> {

    /**
     * 根据用户id和状态查询并分页
     */
    @Select("<script>" +
            "select * from convention co " +
            "<where>" +
            "co.user_id = #{userId} " +
            "and co.del = 0 " +
            "<if test ='state != null'>" +
            "and co.state = #{state}" +
            "</if>" +
            "</where>" +
            "order by co.create_time desc" +
            "</script>")
    Page<Convention> selectPage(Page<Convention> page, Integer userId, Integer state);

    /**
     * 根据用户id查询总条数
     */
    @Select("<script>" +
            "select count(*) from convention co " +
            "<where> " +
            "co.user_id = #{userId} " +
            "and co.del = 0 " +
            "<if test ='state != null'>" +
            "and co.state = #{state} " +
            "</if>" +
            "</where>" +
            "</script>")
    Integer selectCount(Integer userId, Integer state);
}

